package com.diors.commons.network;

import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;

/**
 * 网络连接超类
 * @author	darren.ouyang <ouyang.darren@gmail.com>
 * @date	2013-10-21
 * @version 1.0
 * @copyright Copyright (c) 2013, darren.ouyang
 */
public abstract class AbstractConnection 
{

	ChannelHandlerContext context;
	
	Channel channel;
	
	/* 读取流 */
	ChannelBuffer readBuffer;

	/* 写入流 */
	ChannelBuffer writeBuffer;
	
	/* 连接的IP */
	String ip;
	
	/**
	 * 获取连接唯一ID
	 * @return
	 * @create	2013-10-21	darren.ouyang
	 */
	public int getBaseID ()
	{
		return channel.getId();
	}
	
	@Override
	public String toString() 
	{
		StringBuilder sb = new StringBuilder("标示ID[").append(getBaseID()).
				append("]IP[").append(ip).append("]readerIndex[").append(readBuffer.readerIndex()).
				append("]writerIndex[").append(writeBuffer.writerIndex()).append("]");
		
		return sb.toString();
	}
}
